import fs from "fs";
import path from "path";
console.log('process.argv', process.argv)

export default function readConfig<T=any>(propPath?: string):any{
  const fileName = './api2type.config.json';
  try{
    const data = fs.readFileSync(path.resolve('./',fileName), 'utf8');
    if (!propPath) return data; 
    const propArr = propPath.split(".");
    let finalVal = JSON.parse(data);
    for (const prop of propArr) {

      if (!finalVal?.hasOwnProperty?.(prop))  return null;
      finalVal = finalVal?.[prop];
    }
    return finalVal;
  } catch {
    return null;
  }
}